import 'sale_item.dart';

class SaleRecord {
  final String id;
  final String customerName;
  final DateTime date;
  final List<SaleItem> items;
  final double totalAmount;
  final String paymentMethod;
  final String status;

  SaleRecord({
    required this.id,
    required this.customerName,
    required this.date,
    required this.items,
    required this.totalAmount,
    required this.paymentMethod,
    required this.status,
  });

  factory SaleRecord.fromJson(Map<String, dynamic> json) {
    return SaleRecord(
      id: json['id'] as String,
      customerName: json['customerName'] as String,
      date: DateTime.parse(json['date'] as String),
      items: (json['items'] as List)
          .map((item) => SaleItem.fromJson(item as Map<String, dynamic>))
          .toList(),
      totalAmount: (json['totalAmount'] as num).toDouble(),
      paymentMethod: json['paymentMethod'] as String,
      status: json['status'] as String,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'customerName': customerName,
      'date': date.toIso8601String(),
      'items': items.map((item) => item.toJson()).toList(),
      'totalAmount': totalAmount,
      'paymentMethod': paymentMethod,
      'status': status,
    };
  }
} 